package com.ies.ieschool.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.CssResource.NotStrict;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.ies.ieschool.client.dto.NavigationListGridRecordDTO;
import com.ies.ieschool.client.module.academic.view.content.CourseView;
import com.ies.ieschool.client.module.academic.view.data.NavigationAcademicData;
import com.ies.ieschool.client.module.academic.view.data.NavigationGeneralData;
import com.ies.ieschool.client.module.academic.view.data.NavigationStatisticData;
import com.ies.ieschool.client.object.ContextAreaFactory;
import com.ies.ieschool.client.view.ApplicationMenuView;
import com.ies.ieschool.client.view.HeadView;
import com.ies.ieschool.client.view.NavigationView;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.menu.Menu;
/**
 * <p>
 * Title: �к���èѴ��çҹ�ç���¹
 * Description: View �ͧ˹����ѡ�ͧ ��ͧ�Ԫҡ��
 * Copyright: Copyright (c) 2554
 * Company: Intelligent Enterprise Software
 * @author Sharif Densumite
 * @version IES 2012
 * @since 5-04-2012
 */

public class IESCHOOL implements EntryPoint {
	
	private static final int NORTH_HEIGHT = 85; // HEAD_HEIGHT + // APPLICATION_MENU_HEIGHT

	private VLayout mainLayout;
	private HLayout northLayout;
	private HLayout southLayout;
	private VLayout eastLayout;
	private VLayout westLayout;

	ApplicationMenuView applicationMenu;

	public void onModuleLoad() {

		GWT.log("init OnLoadModule()...", null);

		// get rid of scroll bars, and clear out the window's built-in margin,
		// because we want to take advantage of the entire client area
		//Window.enableScrolling(false);
		Window.setMargin("0px");

		// initialise the main layout container
		mainLayout = new VLayout();
		mainLayout.setWidth100();
		mainLayout.setHeight100();

		// initialise the North layout container
		northLayout = new HLayout();
		northLayout.setHeight(NORTH_HEIGHT);

		VLayout vLayout = new VLayout();
		// add the Masthead to the nested layout container
		vLayout.addMember(new HeadView("ห้องวิชาการ"));
		// add the Application menu to the nested layout container
		applicationMenu = new ApplicationMenuView();

		vLayout.addMember(applicationMenu);
		// add the nested layout container to the North layout container
		northLayout.addMember(vLayout);

		// initialise the West layout container
		NavigationView uiNavigator = new NavigationView();
		uiNavigator.add("งานวิชาการ",NavigationAcademicData.getRecords(), new UINavigatorClickHandler());
		uiNavigator.add("งานสถิติ",NavigationStatisticData.getRecords(), new UINavigatorClickHandler());		
		uiNavigator.addPrayingtime();
		uiNavigator.expandSection(0);
		westLayout = uiNavigator;
		// initialise the East layout container
		eastLayout = new CourseView();

		// initialise the South layout container
		southLayout = new HLayout();

		// set the Navigation Pane and ContextArea as members of the South
		// layout container
		southLayout.setMembers(westLayout, eastLayout);

		// add the North and South layout containers to the main layout
		// container
		mainLayout.addMember(northLayout);
		mainLayout.addMember(southLayout);

		// add the main layout container to GWT's root panel
		RootLayoutPanel.get().add(mainLayout);
	}

	private class UINavigatorClickHandler implements RecordClickHandler {
		@Override
		public void onRecordClick(RecordClickEvent event) {
			NavigationListGridRecordDTO record = (NavigationListGridRecordDTO) event
					.getRecord();
			setContextAreaView(record);
		}
	}

	private void setContextAreaView(NavigationListGridRecordDTO record) {
		ContextAreaFactory factory = record.getFactory();
		Canvas view = factory.create();
		southLayout.setMembers(westLayout, view);
	}
}
